<cfset PrimaryKeyExists = false /><cfset fk_list = "" />
<cfset model = deserializeJSON(generated_mdl) />

<cfloop collection="#model#" item="idx">
	<cfset props = model["#idx#"] />
	<cfset mdl = "#idx#" />
</cfloop>

<cfset formatter =  Application.Utils.Formatter.init() />
<cfoutput>

<cfsavecontent variable="indexContent">
&lt;h2&gt;Index : #formatter.Capitalize(form.table_name)#&lt;/h2&gt;

&lt;cfset #form.table_name# = createObject("component",'##application.env.component_location##.app.controller.#form.table_name#_controller') /&gt;
&lt;cfset qry#form.model_name#_readall = "###form.table_name#.index()##" /&gt;

&lt;table&gt;
	&lt;tr&gt;
		&lt;td colspan="#structCount(props)#" valign="top" align="center"&gt;
			&lt;cfoutput&gt;##application.utils.get_links('#form.table_name#').new##&lt;/cfoutput&gt;
		&lt;/td&gt;
		&lt;td valign="top"&gt;&nbsp;&lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr&gt;
	<cfloop collection="#props#" item="i">
	&lt;th valign="top" align="center"&gt;#rereplace(formatter.Capitalize(i),'^[\s]*$','','all')#&lt;/th&gt;
	</cfloop>
		&lt;th valign="top"&gt;&nbsp;&lt;/th&gt;
	&lt;/tr&gt;

	&lt;cfoutput query="qry#form.model_name#_readall"&gt;
	&lt;tr&gt;
		<cfloop collection="#props#" item="i">
		&lt;td align="left" valign="top"&gt;
			<cfif structKeyExists(props[i], 'mapping')><cfif listLen(props[i]['mapping']) GTE 2><cfloop list="#props[i]['mapping']#" index="mapped_column">###mapped_column### </cfloop><cfelse>###props[i]['mapping']###</cfif><cfelse>###i###</cfif>
		&lt;/td&gt;
		</cfloop>
		&lt;td valign="top"&gt;
		<cfloop collection="#props#" item="columns">
			<cfif (structkeyExists(props[columns],'key') and props[columns]['key'] eq "primary")>
				<cfset PrimaryKeyExists = true />
				&lt;!--- todo: Need not call the function three times, as it returns an array of all links ---&gt;
				##application.utils.get_links('#form.table_name#',#columns#).show## |
				##application.utils.get_links('#form.table_name#',#columns#).edit## |
				##application.utils.get_links('#form.table_name#',#columns#).delete##
			<cfelseif structKeyExists(props[i], 'key') AND props[i]['key'] EQ 'foreign' AND PrimaryKeyExists EQ false>
				<cfset fk_list = listAppend(fk_list,"#columns#/##" & columns & "##/") />
			</cfif>
		</cfloop>
		<cfif listlen(fk_list) GT 0>
				&lt;!--- todo: Need not call the function three times, as it returns an array of all links ---&gt;
				##application.utils.get_links('#form.table_name#',"#rereplace(fk_list,',','','ALL')#").show## |
				##application.utils.get_links('#form.table_name#',"#rereplace(fk_list,',','','ALL')#").edit## |
				##application.utils.get_links('#form.table_name#',"#rereplace(fk_list,',','','ALL')#").delete##
		</cfif>	
		
		&lt;/th&gt;
	&lt;/tr&gt;
	&lt;/cfoutput&gt;
&lt;/table&gt;	
<hr noshade="true" />
&lt;cfdump var="###form.table_name#.index()##"/&gt;
</cfsavecontent>


<cfsavecontent variable="newFormContentWrapper">
&lt;h2&gt;New #form.model_name#&lt;/h2&gt;
&lt;cfform action="##application.utils.get_paths('#form.table_name#').create##" method="POST"&gt;
	&lt;cfinclude template="newContent.cfm" /&gt;
&lt;/cfform&gt;
</cfsavecontent>


<cfsavecontent variable="newFormContent">
&lt;table&gt;
&lt;caption&gt;Create new #formatter.Capitalize(mdl)#&lt;/caption&gt;
<cfloop collection="#props#" item="i">
	<cfif (structkeyExists(props[i],'key') and props[i]['key'] eq "primary")>
		<cfif (not structkeyExists(props[i],'identity')) or props[i]['identity'] neq true>
		&lt;tr&gt;
			&lt;td align="right" valign="top"&gt;
				#formatter.Capitalize(i)#: 
			&lt;/td&gt;
			&lt;td align="left" valign="top"&gt; 
				&lt;cfinput type="text" id="#i#" name="#i#" value="#props[i]['value']#" 
				<cfif structKeyExists(props[i],'required') and props[i]['required'] eq true>required="#props[i]['required']#" message="The '#rereplace(i,'_',' ','ALL')#' field is required."</cfif>
				<cfif structKeyExists(props[i],'maxlength')>maxlength="#props[i]['maxlength']#"</cfif> /&gt;
				<cfif structKeyExists(props[i],'required') and props[i]['required'] eq true>&lt;div style="color:red;font-size:8pt;"&gt;[required]&lt;/div&gt;</cfif>
			&lt;/td&gt;
		&lt;/tr&gt;
		</cfif>
	<cfelseif  NOT (structkeyExists(props[i],'key') and props[i]['key'] eq "primary")>
	&lt;tr&gt;
		&lt;td align="right" valign="top"&gt;
			#formatter.Capitalize(i)#:
		&lt;/td&gt;
		&lt;td align="left" valign="top"&gt;
		<cfif structKeyExists(props[i], 'key') AND props[i]['key'] EQ 'foreign'>
			&lt;cfset dependency_obj = createObject("component",'##application.env.component_location##.app.controller.#left(props[i]["references"],refind("\.",props[i]["references"])-1)#_controller').index() /&gt;
			&lt;select name="#i#"&gt;
				&lt;option value="-1"&gt;Select Below&lt;/option&gt;
				&lt;cfoutput query="dependency_obj"&gt;
					&lt;option value="###right(props[i]['references'],len(props[i]['references'])-refind('\.',props[i]['references']))###"&gt;
						<cfif structKeyExists(props[i], 'mapping')><cfif listLen(props[i]['mapping']) GTE 2><cfloop list="#props[i]['mapping']#" index="mapped_column">###mapped_column###</cfloop><cfelse>###props[i]['mapping']###</cfif><cfelse>###i###</cfif>
					&lt;/option&gt;
				&lt;/cfoutput&gt;
			&lt;/select&gt;
			<cfif structKeyExists(props[i], 'key') AND props[i]['key'] EQ 'foreign'>
				&lt;div style="color:green;font-size:8pt;"&gt;
				
<!--- todo:use links() function here 
				<cfif form.pretty_urls eq true>
				&lt;a href="http://#cgi.server_name##port##app_path#/#left(props[i]['references'],refind("\.",props[i]['references'])-1)#/new"&gt;Create #left(props[i]['references'],refind("\.",props[i]['references'])-1)#&lt;/a&gt;
				<cfelse>
				&lt;a href="http://#cgi.server_name##port##app_path#/index.cfm?#left(props[i]['references'],refind("\.",props[i]['references'])-1)#/new"&gt;Create #left(props[i]['references'],refind("\.",props[i]['references'])-1)#&lt;/a&gt;
				</cfif>
 --->
				&lt;/div&gt;
			</cfif>
		<cfelse>
			<cfif structKeyExists(props[i], 'default') AND props[i]['default'] EQ 'current_timestamp'>
				<cfset props[i]['value'] = "#dateFormat(now(),'mm/dd/yyyy')# #timeFormat(now(),'HH:mm:ss')#" />
			<cfelseif structKeyExists(props[i], 'default') AND props[i]['default'] neq "">
				<cfset props[i]['value'] = props[i]['default'] />
			<cfelse>
				<cfset props[i]['value'] = "" />
			</cfif>
			<cfif listContainsNoCase('varchar,integer,decimal,float,datetime,timestamp,date',props[i]['type'])>
			&lt;cfinput type="text" id="#i#" name="#i#" value="#props[i]['value']#" 
			<cfif structKeyExists(props[i],'required') and props[i]['required'] eq true>required="#props[i]['required']#" message="The '#rereplace(i,'_',' ','ALL')#' field is required."</cfif>
			<cfif structKeyExists(props[i],'maxlength')>maxlength="#props[i]['maxlength']#"</cfif> /&gt;
				<cfif structKeyExists(props[i],'required') and props[i]['required'] eq true>&lt;div style="color:red;font-size:8pt;"&gt;[required]&lt;/div&gt;</cfif>
			<cfelseif listContainsNoCase('textarea,longvarchar',props[i]['type'])>
			&lt;textarea id="#i#" name="#i#"&gt;#props[i]['value']#&lt;/textarea&gt;
			<cfelseif listContainsNoCase('bit,boolean',props[i]['type'])>
			&lt;cfinput type="checkbox" name="#i#" value="true" <cfif structKeyExists(props[i], 'default')>checked="#props[i]['default']#"</cfif> /&gt;
			<cfelse>
				* Could not generate field.
			</cfif>
		</cfif>
		&lt;/td&gt;
	&lt;/tr&gt;
</cfif></cfloop>
	&lt;tr&gt;
		&lt;td colspan="2" align="right"&gt;
			&lt;cfoutput&gt;##application.utils.get_links('#form.table_name#').back##&lt;/cfoutput&gt;
			&lt;input type="submit" id="btn_submit" name="submit" value="Submit" /&gt;
			&lt;input type="reset" id="btn_reset" name="reset" value="Reset" /&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
</cfsavecontent>

<cfsavecontent variable="showFormContent">
&lt;h2&gt;Details: #formatter.Capitalize(mdl)# &lt;/h2&gt;
&lt;cfset #form.model_name# = createObject("component",'##application.env.component_location##.app.controller.#form.table_name#_controller') /&gt;
&lt;cfset qry#form.model_name#_read = "###form.model_name#.show(request.id)##" /&gt;

&lt;table&gt;

	&lt;cfoutput query="qry#form.model_name#_read"&gt;
	&lt;tr&gt;
		&lt;td colspan="2" align="center" valign="top"&gt;	
			&lt;!--- TODO: Use the links from helper file here request.utils.get_links() ---&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	<cfloop collection="#props#" item="i">
	&lt;tr&gt;
		&lt;td align="right" valign="top"&gt;
			#formatter.Capitalize(i)#:
		&lt;/td&gt;
		&lt;td align="left" valign="top"&gt;
			###i###
		&lt;/td&gt;
	&lt;/tr&gt;
	</cfloop>
	&lt;/cfoutput&gt;
	&lt;tr&gt;
		&lt;td colspan="2" align="center"&gt;
			&lt;cfoutput&gt;
				##application.utils.get_links('#form.table_name#').back## |
				##application.utils.get_links('#form.table_name#').new## |
				##application.utils.get_links('#form.table_name#','##request.id##').edit##
			&lt;/cfoutput&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
<hr noshade="true"/>
&lt;cfdump var="###form.model_name#.show(request.id)##"/&gt;
</cfsavecontent>

<cfset input_format = "text" />
<cfsavecontent variable="editFormContentWrapper">
&lt;h2&gt;Edit Form&lt;/h2&gt;
&lt;cfset #form.model_name# = createObject("component",'##application.env.component_location##.app.controller.#form.table_name#_controller') /&gt;
&lt;cfset qry#form.model_name#_read = "###form.model_name#.show(request.id)##" /&gt;
&lt;!--- TODO: Use the links from helper file here request.utils.get_links() ---&gt;
&lt;cfform action="##application.utils.get_paths('#form.table_name#').update##" method="POST"&gt;
	&lt;cfinclude template="editContent.cfm" /&gt;
&lt;/cfform&gt;
<hr noshade="true"/>
&lt;cfdump var="###form.model_name#.show(request.id)##"/&gt;
</cfsavecontent>

<cfsavecontent variable="editFormContent">
&lt;table&gt;
&lt;caption&gt;#formatter.Capitalize(mdl)#&lt;/caption&gt;
	&lt;cfoutput query="qry#form.model_name#_read"&gt;
	<cfloop collection="#props#" item="i"><cfif structKeyExists(props[i],'key') and props[i]['key'] eq "primary">
			<cfset input_format = "hidden" />
		<cfelse>
			<cfset input_format = "text" />
		</cfif>
	&lt;tr&gt;
		&lt;td align="right" valign="top"&gt;
			<cfif NOT (structKeyExists(props[i],'key') and props[i]['key'] eq "primary")>#formatter.Capitalize(i)#:</cfif>
		&lt;/td&gt;
		&lt;td align="left" valign="top"&gt;
		<cfif structKeyExists(props[i], 'key') AND props[i]['key'] EQ 'foreign'>
			&lt;cfset current_id = "###i###" /&gt;
			&lt;cfset dependency_obj = createObject("component",'##application.env.component_location##.app.dao.#left(props[i]["references"],refind("\.",props[i]["references"])-1)#').readAll() /&gt;
			&lt;select name="#i#"&gt;
				&lt;option value="-1"&gt;Select Below&lt;/option&gt;
				&lt;cfloop query="dependency_obj"&gt;
					&lt;option value="###right(props[i]['references'],len(props[i]['references'])-refind('\.',props[i]['references']))###" &lt;cfif current_id eq ###right(props[i]['references'],len(props[i]['references'])-refind('\.',props[i]['references']))###&gt;selected="true"&lt;/cfif&gt;&gt;
					<cfif structKeyExists(props[i], 'mapping')><cfif listLen(props[i]['mapping']) GTE 2><cfloop list="#props[i]['mapping']#" index="mapped_column">###mapped_column### </cfloop><cfelse>###props[i]['mapping']###</cfif><cfelse>###i###</cfif>
					&lt;/option&gt;
				&lt;/cfloop&gt;
			&lt;/select&gt;
			<cfif structKeyExists(props[i], 'key') AND props[i]['key'] EQ 'foreign'>
				&lt;div style="color:green;font-size:8pt;"&gt;
				<cfset port = iif(cgi.SERVER_PORT neq 80, DE(':#cgi.server_port#'), DE('')) />
<!--- todo: function to generate links 
				<cfif form.pretty_urls eq true>
				&lt;a href="http://#cgi.server_name##port##app_path#/#left(props[i]['references'],refind("\.",props[i]['references'])-1)#/new"&gt;Create #left(props[i]['references'],refind("\.",props[i]['references'])-1)#&lt;/a&gt;
				<cfelse>
				&lt;a href="http://#cgi.server_name##port##app_path#/index.cfm?#left(props[i]['references'],refind("\.",props[i]['references'])-1)#/new"&gt;Create #left(props[i]['references'],refind("\.",props[i]['references'])-1)#&lt;/a&gt;
				</cfif>
 --->
				&lt;/div&gt;
				<cfif PrimaryKeyExists eq false>&lt;cfinput type="hidden" name="old_#i#" value="###i###" /&gt;</cfif>
			</cfif>
		<cfelse>
			<cfif structKeyExists(props[i], 'default')><cfset props[i]['value'] = "##" & props[i]['default'] & "##" /></cfif>
			<cfif listContainsNoCase('textarea,varchar,integer,decimal,float,datetime,date,timestamp',props[i]['type'])>
				&lt;cfinput type="#input_format#" id="#i#" name="#i#" value="###i###" <cfif structKeyExists(props[i],'required') and props[i]['required'] eq true>required="#props[i]['required']#" message="The '#rereplace(i,'_',' ','ALL')#' field is required."</cfif> <cfif structKeyExists(props[i],'maxlength')>maxlength="#props[i]['maxlength']#"</cfif>/&gt;
				<cfif NOT (structKeyExists(props[i],'key') and props[i]['key'] eq "primary") AND (structKeyExists(props[i],'required') and props[i]['required'] eq true)>&lt;div style="color:red;font-size:8pt;"&gt;[required]&lt;/div&gt;</cfif>			
			<cfelseif listContainsNoCase('textarea,longvarchar',props[i]['type'])>
				&lt;textarea id="#i#" name="#i#"&gt;###i###&lt;/textarea&gt;
			<cfelse>
				&lt;cfinput type="checkbox" name="#i#" value="true" checked="###i###" /&gt;
			</cfif>
		</cfif>
		&lt;/td&gt;
	&lt;/tr&gt;
</cfloop>
	&lt;/cfoutput&gt;
	&lt;tr&gt;
		&lt;td colspan="2" align="right"&gt;
			&lt;cfoutput&gt;##application.utils.get_links('#form.table_name#').cancel##&lt;/cfoutput&gt;
			&lt;cfinput type="submit" id="btn_submit" name="submit" value="Submit" /&gt;
			&lt;cfinput type="reset" id="btn_reset" name="reset" value="Reset" /&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
</cfsavecontent>
<cfsavecontent variable="updateActionContent">
&lt;h2&gt;Update Action&lt;/h2&gt;
&lt;cfset ctrl_#form.table_name# = createObject("component",'##application.env.component_location##.app.controller.#form.table_name#_controller').update(form) /&gt;
<div align="center">
	&lt;cfoutput&gt;##application.utils.get_links('#form.table_name#').index## | ##application.utils.get_links('#form.table_name#').new##&lt;/cfoutput&gt;
</div>
</cfsavecontent>
<cfsavecontent variable="deleteActionContent">
&lt;h2&gt;Delete Action&lt;/h2&gt;
&lt;cfset ctrl_#form.table_name# = createObject("component",'##application.env.component_location##.app.controller.#form.table_name#_controller').delete(request.id) /&gt;
<div align="center">
	&lt;cfoutput&gt;##application.utils.get_links('#form.table_name#').index## | ##application.utils.get_links('#form.table_name#').new##&lt;/cfoutput&gt;
</div>
</cfsavecontent>
<cfsavecontent variable="createActionContent">
&lt;h2&gt;Create Action&lt;/h2&gt;
&lt;cfset ctrl_#form.table_name# = createObject("component",'##application.env.component_location##.app.controller.#form.table_name#_controller').create(form) /&gt;
<div align="center">
	&lt;cfoutput&gt;##application.utils.get_links('#form.table_name#').index## | ##application.utils.get_links('#form.table_name#').new##&lt;/cfoutput&gt;
</div>
</cfsavecontent>
</cfoutput>